Difference
In C + + for a class, for the members, use the dot operator. To obtain,
For a pointer to a class object, the arrow operator-> the member of the object to which the pointer points.
When the class defines-> overloaded operators, you can
The arrow operators are different. It might behave like a two-dollar operator: Accept an object and a member name, and dereference the object to get the member. the arrow operator does not accept explicit parameters, regardless of appearance. There
I love thinking in series, so I started this name. The idea of this article is also part of this set of books, for example, comparison, or in-depth mining, or to make up for wisdom, or to make sense, including thinking in C ++, it even includes
15. C ++-Operator Overloading and 15. c Operator Overloading
First, recall the previously learned function overloading.
Function overload
The essence of function Overloading isIndependent Functions
PassFunction NameAndFunction ParametersTo
In C ++, the arrow operator (->) vs the vertex operator (.)
A pointer is displayed on the left.An object is on the left.If P is a pointer, p-> function ();If P is an object, P. function (); Remember-> the left must be a pointer, and the left must
One operator overload
1 Definition of the string class:
# Include
Class string;
Istream & operator> (istream &, string &);
Ostream & operator
Class string {Public:// Overload set of the constructorString (const char * = 0 );String (const string
Heavy-duty operators are good young people, but we often write a lot of repeated code for heavy-duty operators. This is boring, but it is also necessary. The more you load, the greater the elasticity of your class. However, you cannot do whatever
From the beginning, the arrows are part of the JavaScript, and in the first JavaScript it is recommended that you wrap the inline script code in an HTML annotation, which prevents browsers that do not support JavaScript from incorrectly dropping
Operator overloading is a frequently used knowledge point in C + + and an important support point for C + + extensibility.Today I'm going to apply the operator overloading in all cases, for example, and then we'll know the power of operator
1. Increment decrement operatorThe C + + language does not require that the increment decrement operator be a member of a class. But because they change exactly the state of the object being manipulated. Therefore, it is recommended to set the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.